namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Contracts.Interfaces;
    using Resources;

    
    public sealed class DemobilizerTopSpeed<T> : FeatureBase<object>
    {
        public DemobilizerTopSpeed(){}

        public DemobilizerTopSpeed(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Top speed"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Engine; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.DemobilizerTopSpeed; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (robot == null || agent == null) return;

            // Bonuses from extensions
            double extensionBonus = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType);

            // Bonuses from robot
            double robotBonus = robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Module, this.FeatureType);

            double temp = (1 + (double)Value)  / (1 + ((Math.Abs(extensionBonus)) + (Math.Abs(robotBonus))));
            temp = 1 - temp;


            ModifiedValue = IsRounded
                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                : Math.Round(temp, 2);
        }
        public override string FormattedValue
        {
            get { return String.Format("{0} {1}", IsModified ? (double)ModifiedValue * 100 : (double)Value * 100, Unit); }
        }

    }
}